package Persistance;

import java.util.Properties;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.Serializable;

public class Configuration implements Serializable {

    //private static Logger logger = Logger.getLogger("MovieSystem.Persistance.Configuration");

    Properties prop;

    public Properties initProperties(String fileName) throws IOException {
        prop = new Properties();
        try{
            FileInputStream in = new FileInputStream(fileName);
            prop.load(in);
            in.close();
        }
        catch(IOException e){
            //logger.error("Starter encountered an error while trying to load configuration file. please check consistency of the file and file name");
            throw e;
        }
        return prop;
    }

    public String getProperty(String name, String def){
        if (prop != null) {
            String val = prop.getProperty(name);
            if (val != null)
                return val;
        }
        return def;
    }

    public String getLoggerFilename(){
        return getProperty("LoggerFile","LoggerOutput.log");    
    }

    public String getLoggerPattern(){
        return getProperty("LoggerPattern",null);
    }

    public String getLoggerLevel(){
        return getProperty("LoggerLevel","DEBUG");
    }

    public String getMySqlAddress() {
        return getProperty("MySqlAdress","localhost");
    }

    public String getMySqlPort() {
        return getProperty("MySqlPort","3306");
    }

    public String getMySqlUser() {
        return getProperty("MySqlUser","Grupi");
    }

    public String getMySqlPassword() {
        return getProperty("MySqlPassword","RU{)e27v");
    }

    public String getMySqlSchema() {
        return getProperty("MySqlSchema","Grupi");
    }

    public int getMinimumRecommendations() {
        return Integer.parseInt(getProperty("MinimumRecommendations", "10"));
    }

    public int getListLength() {
        return Integer.parseInt(getProperty("ListLength", "10"));
    }

    public int getAlgoParam() {
        return Integer.parseInt(getProperty("AlgoParam", "0"));
    }
}

